<?php

// +----------------------------------------------------------------------

// | Description: 网络推广部---中台系统和财务银盛支付系统的接口对接页面

// +----------------------------------------------------------------------

// | Author: zl

// +----------------------------------------------------------------------



namespace app\crm\controller;



use app\admin\controller\ApiCommon;

use app\crm\model\Customer as CustomerModel;

use app\crm\model\CustomerConfig as CustomerConfigModel;

use app\crm\model\CustomerGrade as CustomerGradeModel;

use think\response\Json;

use think\facade\Db;

use app\admin\model\Coupon as CouponModel;

use app\common\traits\ActionRecordTrait;
use app\shop\model\RefundPayModel;

class SkPayAPIy extends ApiCommon

{
    protected $customerModel;

    protected $customerConfigModel;

    /**

     * 用于判断权限

     * @permission 无限制

     * @allow 登录用户可访问

     * @other 其他根据系统设置

     **/

    public function initialize()

    {

        $action = [

            'permission' => ['skpayapik','returnskpayjg'],

            'allow' => ['users', 'info']

        ];

        event('CheckAuth',$action);

        $request = $this->request;

        $a = strtolower($request->action());



        $this->customerModel = new CustomerModel();

        $this->customerConfigModel = new CustomerConfigModel();

        if (!in_array($a, $action['permission'])) {

            parent::initialize();

        }

    }
	
	

	public function skpayapik()
	{
		
		$pay_demo = new RefundPayModel();
		
		//$key = $pay_demo->demo();
		
		//echo '收款支付API';
		
		$myParams = array();
		$myParams['charset'] = 'UTF-8';
		$myParams['method'] = 'ysepay.online.barcodepay';
		$myParams['partner_id'] = 826491772980273;
		$myParams['sign_type'] = 'RSA';
		$myParams['timestamp'] = date('Y-m-d H:i:s', time());
		$myParams['version'] = '3.0';
		$myParams['notify_url'] = 'https://sunburn.178590.com/crm/SkPayAPIy/returnskpayjg';
		$biz_content_arr = array(
			"out_trade_no" => $pay_demo->datetime2string(date('Y-m-d H:i:s')),
			"shopdate" => $pay_demo->datetime2string(date('Ymd')),
			"subject" => "测试反扫",
			"total_amount" => "0.02",
			"seller_id" => 826491772980273,
			"seller_name" => '郑州市中原区嘉氏堂美容店',
			"timeout_express" => "24h",
			"business_code" => "00510030",
			"bank_type" => "1902000",  //微信
			//"auth_code" => "134707877954377268",
			//"device_info" => "cs002356",  //终端设备号，中国银联时必填
		);
		$myParams['biz_content'] = json_encode($biz_content_arr, JSON_UNESCAPED_UNICODE);//构造字符串
		ksort($myParams);
		var_dump($myParams);
		$signStr = "";
		foreach ($myParams as $key => $val) {
			$signStr .= $key . '=' . $val . '&';
		}
		$signStr = rtrim($signStr, '&');
		//var_dump($signStr);exit;
		$sign = $pay_demo->sign_encrypt(array('data' => $signStr));

		$myParams['sign'] = trim($sign['check']);

		//var_dump($myParams);
		$result = $pay_demo->post_url('https://qrcode.ysepay.com/gateway.do', $myParams, 'ysepay_online_barcodepay_response');
		
		return $result;
		
		var_dump($result);
	}
	
	
	public function returnskpayjg(){
		
		//https://sunburn.178590.com/crm/SkPayAPIy/returnskpayjg
		
	}
	
	
	
}